package com.yscp.ysdemo.utils;

import com.yscp.ysdemo.dto.LoginUser;
import com.yscp.ysdemo.entity.User;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public final class UserHolder {
   private UserHolder(){};

   public static User getUser(){
       Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
       LoginUser loginUser = (LoginUser) authentication.getPrincipal();
       return loginUser.getUser();
   }

    public static LoginUser getLoginUser(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
        return loginUser;
    }
}
